<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const arr = [1, 1, '1', 17, true, true, false, false, 'true', 'a', {}, {}];
        // 方法一：利用Set
        const arr1 = Array.from(new Set(arr));
        console.log(arr1);
        // 方法二：双层for循环+splice
        const arr2 = [1, 1, '1', 17, true, true, false, false, 'true', 'a', {}, {}];
        const unique1 = arr => {
            let len = arr.length;
            for (let i = 0; i < len; i++) {
                for (let j = i + 1; j < len; j++) {
                    if (arr[i] === arr[j]) {
                        arr.splice(j, 1);
                        len--;
                        j--;
                    }
                }
            }
            return arr;
        }
        // 方法三：利用indexOf 或 include
        // indexOf 
        const ind = arr => {
            const res = [];
            for (let i = 0; i < arr.length; i++) {
                if (res.indexOf(arr[i]) === -1) res.push(arr[i]);
            }
            return res;
        }
        console.log(ind);

        // include
        const inc = arr => {
            const res = [];
            for (let i = 0; i < arr.length; i++) {
                if (!res.includes(arr[i])) res.push(arr[i]);
            }
            return res;
        }
        console.log(inc);
        // 方法四：利用Map
        const newArr = arr => {
            const map = new Map();
            const res = [];
            for (let i = 0; i < arr.length; i++) {
                if (!map.has(arr[i])) {
                    map.set(arr[i], true);
                    res.push(arr[i]);
                }
            }
            return res;
        }
        console.log(newArr);
    </script>
</body>

</html>